#pragma once

namespace cs
{
	class CMAuthSession;
	class CMCharEnum;
	class CMPlayerLogin;
}

namespace player
{

	class Session;
	class PlayerMgr : public cftf::util::Singleton<PlayerMgr>
	{
		friend class cftf::util::Singleton<PlayerMgr>;
		PlayerMgr() {};
	public:
		enum { HID = HID_e::kPlayerMgr };
	public:

		void Init();
		void UnInit();

		void _CMAuthSession(const cftf::net::MsgHdr* hdr, const std::shared_ptr<cs::CMAuthSession>& msg);
		void _CMCharEnum(const cftf::net::MsgHdr* hdr, const std::shared_ptr<cs::CMCharEnum>& msg);
		void _CMPlayerLogin(const cftf::net::MsgHdr* hdr, const std::shared_ptr<cs::CMPlayerLogin>& msg);
		void OnSocketDiscount(int socket_handle);

	private:
		std::shared_ptr<Session> GetSessionBySocket(int socket_handle);
		void InternalAuthSession(int socket_handle, const std::shared_ptr<cs::CMAuthSession> msg, const std::shared_ptr<cftf::mysql::QueryRsp> rsp);
		void InternalCharEnum(int socket_handle, const std::shared_ptr<cs::CMCharEnum> msg, const std::shared_ptr<cftf::mysql::QueryRsp> rsp);
		void HandlePlayerLogin(Session* session);

	private:
		std::map<int, std::shared_ptr<battle::object::Player>> socket_hash_;
		std::map<int, std::shared_ptr<Session>> session_hash_;
		std::shared_ptr<cftf::timer::Attacher> attacher_;
	};

}
